﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Northwind.Repositories;
using Northwind.Repositories.Entity;

namespace jQuery.UI.Grid.Stage2.Controllers
{
    public class HomeController : Controller
    {
        #region Fields
        IProductsRepository _productsRepository;
        #endregion

        #region Constructors
        public HomeController()
            : this(new ProductsRepository())
        {
        }

        public HomeController(IProductsRepository productsRepository)
        {
            _productsRepository = productsRepository;
        }
        #endregion

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Products(int skip, int take, string orderby, string filter)
        {
            return Json(new
            {
                rows = _productsRepository.FindRange(filter, orderby, skip, take),
                count = _productsRepository.GetCount(filter)
            }, JsonRequestBehavior.AllowGet);
        }
    }
}
